<?php

namespace App\Http\Model;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Redis;


class SendPhoneNumber extends Base
{
    protected $table = 'send_phone_number';

    public function __construct(array $attributes = [])
    {
        parent::__construct($this->table, $attributes);
    }

    /*
    * 获取手机号码列表
    * */
    public function getPhoneList()
    {
        $db = DB::table($this->table)->select('id', 'phone', 'city', 'rank', 'status')->get()->toArray();
        return $db;//有记录
    }

    public function getPhoneStatus($phone_id)
    {
        $w['id'] = $phone_id;
        $w['status'] = 0;
        return DB::table($this->table)
            ->where($w)
            ->first();
    }

    public function edit($phone_id,$user_id){
        $w['id'] = $phone_id;
        $d['user_id'] = $user_id;
        $d['status'] = 1;
        $d['updated_at'] = date_ymd();
        return DB::table($this->table)
            ->where($w)
            ->update($d);
    }


    public function set_user_cache($key, $data)
    {
        Redis::hmset($key, $data);
        Redis::expire($key, 900);
        return true;
    }

    public function get_all_cache($key){
       return  Redis::hgetall($key);
    }


}